home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / SciAn / src / util / mkmk.c next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  136 lines

  1. /*mkmk.c
  2.   Eric Pepke
  3.   Takes as input a series of programs and produces bits of the makefile 
  4.   including the .h files.  Writes output to standard output.
  5. */
  6.  
  7. #include <stdio.h>
  8.  
  9. char *pn;        /*Program name*/
  10.  
  11. #define MINTAB    24
  12. #define MAXLINE    77
  13.  
  14. MakeDepend(fn)
  15. char *fn;
  16. /*Emits a series of make dependencies for file fn*/
  17. {
  18.     FILE *inFile;
  19.     char line[401];
  20.     char incFile[401];
  21.     char ccLine[401];
  22.     int ccLineSet = 0;
  23.  
  24.     inFile = fopen(fn, "r");
  25.  
  26.     if (inFile)
  27.     {
  28.     int nc;
  29.     strcpy(incFile, fn);
  30.     incFile[strlen(incFile) - 1] = 'o';
  31.     printf("%s:", incFile);
  32.     nc = strlen(fn) + 1;
  33.     do
  34.     {
  35.         putchar('\t');
  36.         nc /= 8;
  37.         ++nc;
  38.         nc *= 8;
  39.     } while (nc < MINTAB);
  40.     incFile[strlen(incFile) - 1] = 'c';
  41.     printf("%s", incFile);
  42.     nc += strlen(incFile);
  43.  
  44.     /*Depend on $(HFILES)*/
  45.     printf(" $(HFILES)");
  46.     nc += 10;
  47.         
  48.  
  49.     while (fgets(line, 400, inFile))
  50.     {
  51.         if (1 == sscanf(line, "#include %s", incFile))
  52.         {
  53.         if (incFile[0] == '"')
  54.         {
  55.             char *s;
  56.             s = &(incFile[1]);
  57.  
  58.             while (*s)
  59.             {
  60.             if (*s == '"')
  61.             {
  62.                 *s = 0;
  63.             }
  64.             else
  65.             {
  66.                 ++s;
  67.             }
  68.  
  69.             }
  70.             if (nc + strlen(&(incFile[1])) > MAXLINE)
  71.             {
  72.             printf("\\\n");
  73.             nc = 0;
  74.             do
  75.             {
  76.                 putchar('\t');
  77.                 nc /= 8;
  78.                 ++nc;
  79.                 nc *= 8;
  80.             }
  81.             while (nc < MINTAB);
  82.             }
  83.             else
  84.             {
  85.             putchar(' ');
  86.             ++nc;
  87.             }
  88.             printf("%s", &(incFile[1]));
  89.             nc += strlen(&(incFile[1]));
  90.         }
  91.         }
  92.         else if (1 == sscanf(line, "/*$%s", ccLine))
  93.         {
  94.         strcpy(ccLine, line + 3);
  95.         ccLineSet = 1;
  96.         }
  97.     }
  98.     printf("\n");
  99.     nc = 0;
  100.     do
  101.     {
  102.         putchar('\t');
  103.         nc /= 8;
  104.         ++nc;
  105.         nc *= 8;
  106.     }
  107.     while (nc < MINTAB);
  108.     if (ccLineSet)
  109.     {
  110.         printf("%s", ccLine);
  111.     }
  112.     else
  113.     {
  114.         printf("$(CC) $(CFLAGS) %s -c\n", fn);
  115.     }
  116.     }
  117.     else
  118.     {
  119.     fprintf(stderr, "%s: Cannot open file %s\n", pn, fn);
  120.     }
  121. }
  122.  
  123. main(argc, argv)
  124. int argc;
  125. char *argv[];
  126. {
  127.     int k;
  128.     
  129.     pn = argv[0];
  130.  
  131.     for (k = 1; k < argc; ++k)
  132.     {
  133.     MakeDepend(argv[k]);
  134.     }
  135. }
  136.